'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url client/user/pub/testsend 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------
		let url = "https://clue.oceanengine.com/outer/wechat/applet/token/1764943130481672";
		let token = "CC1FF025DE32BDDB57CD7391CE1005DB";
		
		let nonce = 8889;
		let times = vk.pubfn.toDecimal(new Date() / 1000, 0);
		const crypto = require('crypto');
		const sha1 = crypto.createHash('sha1');
		
		let strList = [token, times, nonce];
		strList.sort();
		let buffer = "";
		strList.forEach(str => {
			buffer += str;
		})
		let sign = sha1.update(buffer).digest('hex');
		console.log("sign=", sign);
		

		let reback_url = url + "?timestamp=" + times + "&nonce=" + nonce + "&signature=" + sign;
		
		let jlresult = await uniCloud.httpclient.request(reback_url, {
			method: 'POST',
			data: {
				"clue_token": "1764943032483843,1766067623605271",
				"open_id": "oleeq4qXVal95qPqzWEBt9O9kNfw",
				"event_type": "0", //参考：https://bytedance.feishu.cn/docx/doxcnmjDmhXc1Vial05xpvdu9ed
				"props": {
					// "pay_amount": 0 || 1 //单位：分
				}
			},
			contentType: 'json',
			dataType: 'json'
		})
		console.log("res.jlresult=", jlresult);



		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
